package com.reflex;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class Text {
    public static void main(String[] args) throws Exception {
        // 获取Student的Class对象
        Class<?> aClass = Class.forName("com.reflex.Student");
        // 获取无参构造方法
        Constructor<?> constructor = aClass.getConstructor();
        //通过反射，无参构造方法，实例化对象
        Object object = constructor.newInstance();
        System.out.println("object = " + object);

        //获取全参构造方法
        Constructor<?> constructor1 = aClass.getConstructor(String.class, int.class, char.class);
        //通过反射，全参构造方法，实例化对象
        Object object1 = constructor1.newInstance("张三", 18, '男');
        System.out.println("object1 = " + object1);
    }
}
